Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Urlsession retry strategy #7708

Merged
merged 1 commit into from
Mar 3, 2025
Merged

Urlsession retry strategy #7708

merged 1 commit into from
Mar 3, 2025

Conversation

SteffenErn
Copy link
Contributor

@SteffenErn SteffenErn commented Feb 21, 2025

Adding the ability to retry api calls to Rust. It uses the same retry strategy as the previous URLSession calls.


This change is Reviewable

@SteffenErn SteffenErn added the iOS Issues related to iOS label Feb 21, 2025
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 13 files at r1, all commit messages.
Reviewable status: 11 of 13 files reviewed, 2 unresolved discussions


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

#[no_mangle]
pub unsafe extern "C" fn mullvad_api_retry_strategy_never() -> SwiftRetryStrategy {

We should have # Safety warnings for all these functions marked unsafe
mullvad_api_get_addresses has a good example of what these should cover


ios/MullvadREST/RetryStrategy/RetryStrategy.swift line 25 at r1 (raw file):

        }

        /// The return value of this function *must* be passed to a Rust FFI funciton that will consume it, otherwise it will leak.

nit
funciton

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, we'll have to make sure that the tests in RetryStrategyTests use the rust iterators if possible

Reviewable status: 11 of 13 files reviewed, 2 unresolved discussions (waiting on @SteffenErn)

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 13 of 13 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

Previously, buggmagnet wrote…

We should have # Safety warnings for all these functions marked unsafe
mullvad_api_get_addresses has a good example of what these should cover

+1

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

+1

Under what circumstances would it be unsafe to call this function?

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 13 files at r1, 1 of 2 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

@SteffenErn SteffenErn marked this pull request as ready for review February 25, 2025 08:55
pinkisemils
pinkisemils previously approved these changes Feb 25, 2025
Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 13 files at r1, 1 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

@SteffenErn SteffenErn force-pushed the urlsession-retry-strategy branch from 3380650 to 2092c46 Compare February 25, 2025 09:29
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 3 files at r3.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @buggmagnet and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 48 at r4 (raw file):

/// Creates a retry strategy that never retries after failure.
/// The result needs to be consumed.

Consumed by what? I think this could be elaborated.

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pinkisemils, @rablador, and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):
Technically none of these are inherently unsafe, but to quote the rust documentation

All FFI (Foreign Function Interface) functions are unsafe to call because the other language can do arbitrary operations that the Rust compiler can't check.

We can just state in the # Safety lines that the functions are safe to call, as we do all across our existing Rust codebase.

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

Previously, buggmagnet wrote…

Technically none of these are inherently unsafe, but to quote the rust documentation

All FFI (Foreign Function Interface) functions are unsafe to call because the other language can do arbitrary operations that the Rust compiler can't check.

We can just state in the # Safety lines that the functions are safe to call, as we do all across our existing Rust codebase.

What is the safety hazard in calling this function? I am asking because I want to understand what are you trying to get at.

As far as I can tell, this call is always safe, it will panic and crash badly only in the case where it fails to allocate memory or there is not enough stack space to call it safely. If we are going to document those failure modes, then we can presume that all function calls are not safe. Am I missing something?

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @buggmagnet and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

What is the safety hazard in calling this function? I am asking because I want to understand what are you trying to get at.

As far as I can tell, this call is always safe, it will panic and crash badly only in the case where it fails to allocate memory or there is not enough stack space to call it safely. If we are going to document those failure modes, then we can presume that all function calls are not safe. Am I missing something?

Maybe the correct thing to do here is to not mark these functions as unsafe instead :)

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pinkisemils, @rablador, and @SteffenErn)


mullvad-ios/src/api_client/retry_strategy.rs line 49 at r1 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

Maybe the correct thing to do here is to not mark these functions as unsafe instead :)

Yes if we can do that and have the compiler be happy about it, that would be my preferred option too

@pinkisemils pinkisemils force-pushed the urlsession-retry-strategy branch from 2092c46 to 4c88676 Compare March 3, 2025 08:37
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pinkisemils and @SteffenErn)

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @SteffenErn)

@pinkisemils pinkisemils force-pushed the urlsession-retry-strategy branch from 4c88676 to 68352d1 Compare March 3, 2025 13:23
@pinkisemils pinkisemils merged commit ad9cb78 into main Mar 3, 2025
51 of 53 checks passed
@pinkisemils pinkisemils deleted the urlsession-retry-strategy branch March 3, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants